package com.itheima.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class JdbcDemo1 {

    public static void main(String[] args) throws Exception{
        //注册驱动
        Class.forName("com.mysql.jdbc.Driver");
        //获取连接
        Connection con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/db1", "root", "root");

        //获取执行者
        Statement stat = con.createStatement();
        //执行sql语句,并且接受结果
        String sql = "SELECT * FROM user";
        ResultSet re = stat.executeQuery(sql);
        //处理结果
        while(re.next()){
            System.out.println(re.getInt("id")+"=="+re.getString("name"));
        }
        //释放资源
        re.close();
        stat.close();
        con.close();

    }

}
